import 'package:flutter/material.dart';
import 'dart:async';

class SimpleDialogDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SimpleDialogStateDemo();
  }
}

class SimpleDialogStateDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SimpleDialogState();
  }
}

class SimpleDialogState extends State<SimpleDialogStateDemo> {
  String _choseOption = "Nothing";

  /**
   * 打开simpledialog对话框
   */
  Future _openSimpelDialog() async {
    final option = await showDialog(
      context: context,
      builder: (BuildContext context) {
        return SimpleDialog(
          title: Text('标题'),
          children: <Widget>[
            SimpleDialogOption(
              child: Text(
                '内容-A',
              ),
              onPressed: () {
                Navigator.pop(context, Option.A);
              },
            ),
            SimpleDialogOption(
              child: Text(
                '内容-B',
              ),
              onPressed: () {
                Navigator.pop(context, Option.B);
              },
            ),
            SimpleDialogOption(
              child: Text(
                '内容-C',
              ),
              onPressed: () {
                Navigator.pop(context, Option.C);
              },
            ),
          ],
        );
      },
    );

    switch (option) {
      case Option.A:
        setState(() {
          _choseOption = 'A';
        });
        break;
      case Option.A:
        setState(() {
          _choseOption = 'B';
        });
        break;
      case Option.C:
        setState(() {
          _choseOption = 'C';
        });
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('SimpleDialogDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(8.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You chose content is:  $_choseOption',
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                //TODO
              ],
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _openSimpelDialog();
        },
        child: Icon(Icons.format_list_numbered),
      ),
    );
  }
}

enum Option { A, B, C }
